package com.venue.hjt.venueclass.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.venue.hjt.venueclass.R;
import com.venue.hjt.venueclass.db.VenueBooKing;
import com.venue.hjt.venueclass.utlis.ClassCalendar;

import java.util.List;

/**
 * Created by xqx on 2017/10/25.
 *
 */

public class RecordAdapter extends BaseAdapter {
    private Context mContext;
    private List<VenueBooKing> list;
    String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
    public RecordAdapter(Context mContext, List<VenueBooKing> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHander viewHander;
        if (convertView==null){
            viewHander=new ViewHander();
            convertView= View.inflate(mContext, R.layout.record_item,null);
            viewHander.tv_record_title=convertView.findViewById(R.id.tv_record_title);
            viewHander.tv_record_time=convertView.findViewById(R.id.tv_record_time);
            viewHander.tv_record_to=convertView.findViewById(R.id.tv_record_to);
            convertView.setTag(viewHander);
        }else{
            viewHander= (ViewHander) convertView.getTag();
        }
        VenueBooKing booKing = list.get(position);
        viewHander.tv_record_title.setText(booKing.getGroupname());
        viewHander.tv_record_time.setText(booKing.getDate()+" "+weekDays[ClassCalendar.getWeekDays()]+" "+booKing.getStart_time()+"～"+booKing.getEnd_time());
        int sign = Integer.parseInt(booKing.getSignin());
        int total = Integer.parseInt(booKing.getTotal());
        viewHander.tv_record_to.setText("应到"+booKing.getTotal()+"人/已到"+booKing.getSignin()+"人/未到"+(total-sign)+"人");
        return convertView;
    }
    class ViewHander{
        TextView tv_record_title,tv_record_time,tv_record_to;
    }


}
